package com.ht.sps.nh.module;

import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import java.io.File;

@IocBean
@At("nh/system/homePage")
public class HomePageModule {
    private static final Logger log = LoggerFactory.getLogger(HomePageModule.class);

    @At("/")
    @Ok("th:nh/system/homePage")
    public void index(HttpServletRequest request) {
        request.setAttribute("pic1",png(request,"5"));
    }

    public String png(HttpServletRequest request,String photoName) {
        String path = null;
        if(photoName!=null&&!photoName.equals("")){
            String jpgPath = request.getServletContext().getRealPath("/resources/nh/images/"+photoName+".jpg");
            String pngPath = request.getServletContext().getRealPath("/resources/nh/images/"+photoName+".png");
            if (new File(jpgPath).exists()) {
                path = "/resources/nh/images/"+photoName+".jpg";
            } else if (new File(pngPath).exists()) {
                path = "/resources/nh/images/"+photoName+".png";
            }
        }

        if (path == null) {
            path ="/resources/nh/images/welcome.jpg";
        }

        return path;
    }
}
